package by.grsu.hdm.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import by.grsu.hdm.devices.MediaCenter;

public class MediaPlayer extends HttpServlet
{
	private static final long serialVersionUID = 1L;
	private MediaCenter media = new MediaCenter("MEDIA#6151");
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException
	{
		response.setContentType("text/html");
		
		PrintWriter out = response.getWriter();
		
		String mp3 = request.getParameter("MP3");
		String[] mp3Value = request.getParameterValues("MP3");
		String[] mpgValue = request.getParameterValues("MPG");
		String mpg = request.getParameter("MPG");
		String trackname =request.getParameter("trackname");
		
		out.println("<html>");
        out.println("<head>");
        out.println("<title>Media Player</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h2>Media Player</h2>");
        out.println("<form action=\"MediaPlayer\" method=POST>");
        out.println("Write track name:");
        out.println("<p>");
        out.println("<input type=text size=20 name=trackname>");
        out.println("<p>");
        out.println("OR");
        out.println("<p>");
        out.println("Choose:");
        out.println("<p>");
        out.println("MP3:");
        out.println("<input type = radio name='MP3' value='Billy jean'>Billy jean");
        out.println("<input type = radio name='MP3' value='A moment of madness'>A moment of madness");
        out.println("<input type = radio name='MP3' value='Roar'>Roar");
        out.println("<p>");out.println("<p>");
        
        out.println("MPG:");
        out.println("<input type = radio name='MPG' value='Batleship'>Batleship");
        out.println("<input type = radio name='MPG' value='Run'>Run");
        out.println("<input type = radio name='MPG' value='Property'>Property");

        out.println("<p>");out.println("<p>");
        out.println("<input type=submit value='Play'>");
        out.println("<p>");
       
        if (trackname!= null)
        {
        	media.setSongName(trackname);
        	out.println("<h3>Player play "+media.getSongName()+"</h3>");
        	out.println("<p>");
        }
        if (mp3!= null)
        {
        	media.setSongName("song1");
        	out.println("<h3>Player play "+media.getSongName()+"</h3>");
        	out.println("<p>");
        }
        if (mpg!= null)
        {
        	media.setFilmName("film1");
        	out.println("<h3>Player play "+media.getFilmName()+"</h3>");
        	out.println("<p>");
        }
        
        out.println("</form>");
        out.println("</body>");
        out.println("</html>");
    }

	public void doPost(HttpServletRequest request, HttpServletResponse response)
    		throws IOException, ServletException
    {
        doGet(request, response);
    }

	
    
}
